/**
* @program: src
*
* @description:
*
* @author: Mr.chen
*
* @create: 2020-12-11 17:48
**/
package rpc
import (
	"ydd-im/service/api/services/wsservice/account"
	"ydd-im/service/api/services/wsservice/pb"
	"ydd-im/service/api/tools/response"
	"encoding/json"
	//"github.com/goinggo/mapstructure"
	//"ydd-im/util/response"
	"context"

)
type UserServiceServer struct{}

/**
 * 注册用户
 * @access  public
 * @param   pb.RegisterReq     req  请求参数
 * @return  pb.RegisterResp 自定义数据类型
 * @return  error err 错误信息
 */

func (this *UserServiceServer) Register(ctx context.Context, req *pb.RegisterReq) (*pb.RegisterResp, error) {
	err := account.Register(req.Username,req.Passwd,req.Userkey,req.Appkey)
	if err != nil {
		return 	&pb.RegisterResp{Code:int64(response.ErrorCode),Msg:err.Error()},nil
	}else{
		return &pb.RegisterResp{Code:int64(response.SuccessCode),Msg:"success"}, nil
	}
}

/**
 * 登录
 * @access  public
 * @param   pb.RegisterReq     req  请求参数
 * @return  pb.RegisterResp 自定义数据类型
 * @return  error err 错误信息
 */


func (this *UserServiceServer) Login(ctx context.Context, req *pb.LoginReq) (*pb.LoginResp, error) {
	respon,err := account.Login(req.Username,req.Passwd,req.Client,req.Appkey)
	var loginmodel pb.LoginModel
	if err != nil {
		return 	&pb.LoginResp{Code:int64(response.ErrorCode),Msg:err.Error(),Data:nil},nil
	}
	b, _ := json.Marshal(respon)
	_ = json.Unmarshal(b, &loginmodel)
	return &pb.LoginResp{Code:int64(response.SuccessCode),Msg:"success",Data:&loginmodel}, nil
}